program attack_plus;
uses crt;
var
	blood1, blood2 : integer;
	current : boolean = true;
	damage : integer;
	element1 : integer = 0;
	element2 : integer = 0;
	stop : boolean = false;
const
	elements : array[0..4] of string = ('金', '木', '水', '火', '土');
	color : array[0..4] of integer = (14, 10, 11, 12, 8);
function probability(molecular, denominator : integer) : boolean;
var
	choice : integer;
begin
	choice := random(denominator);
	if choice < molecular then
		probability := true
	else
		probability := false;
end;
function person(present : boolean) : string;
begin
	if present then
		person := '我'
	else
		person := '敌';
end;
function shield(original : integer; present : boolean) : integer;
var
	choice : integer;
	harm : integer;
begin
	if (present and (element2 <> 0)) or (not present and (element1 <> 0)) then
	begin
		shield := -1;
		exit;
	end;
	choice := random(12);
	if choice = 0 then
	begin
		writeln('但是被', person(not present), '方用金能量制成的盾牌华丽地挡了下来！');
		writeln(person(not present), '方未受到伤害！');
		shield := 0;
	end
	else if choice = 1 then
	begin
		harm := original div 2;
		writeln('不过被', person(not present), '方用金能量制成的盾牌勉强挡下来了一部分。');
		writeln(person(not present), '方受到', harm, '点伤害！');
		shield := harm;
	end
	else
		shield := -1;
end;
function fight(element : integer; present : boolean) : integer;
var
	harm : integer;
	defense : integer;
begin
	if (element = 1) and (random(2) = 0) then
	begin
		harm := - random(5) - 1;
		writeln(person(present), '方使用', elements[element], '能量回复了', - harm, '点血量！');
		fight := harm;
		exit;
	end
	else
		write(person(present), '方使用', elements[element], '能量发动攻击，');
	if stop and ((present and (element1 <> 4)) or (not present and (element2 <> 4))) then
	begin
		writeln('但由于处于被束缚状态无法攻击！');
		writeln(person(not present), '方未受到伤害！');
		delay(500);
		writeln(person(present), '方终于挣脱了束缚，可以继续攻击！');
		stop := false;
		fight := 0;
		exit;
	end;
	case element of
		0, 1 : begin
			harm := random(5) + 1;
			defense := shield(harm, present);
		end;
		2 : begin
			if probability(1, 30) then
			begin
				harm := random(20) + 10;
				writeln('致命一击！');
			end
			else
				harm := random(5) + 1;
			defense := shield(harm, present);
		end;
		3 : begin
			harm := random(7);
			defense := shield(harm, present);
		end;
		4 : begin
			harm := random(5) + 1;
			defense := shield(harm, present);
			if defense <> -1 then
				harm := defense
			else
				writeln(person(not present), '方受到', harm, '点伤害！');
			if probability(1, 8) then
			begin
				stop := true;
				writeln(person(not present), '方被土能量缠绕住了，无法脱身！');
			end;
		end;
	end;
	if element <> 4 then
	begin
		if defense = -1 then
			writeln(person(not present), '方受到', harm, '点伤害！')
		else
			harm := defense;
	end;
	fight := harm;
end;
begin
	randomize;
	writeln('无尽袭击 增强版');
	writeln('infinity attack plus');
	delay(500);
	textcolor(15);
	blood1 := random(100) + 100;
	blood2 := random(100) + 100;
	while element1 = element2 do
	begin
		element1 := random(5);
		element2 := random(5);
	end;
	writeln('我方属性：', elements[element1], '，血量：', blood1);
	writeln('敌方属性：', elements[element2], '，血量：', blood2);
	delay(500);
	writeln('战斗开始！');
	while (blood1 > 0) and (blood2 > 0) do
	begin
		delay(500);
		if current then
		begin
			textcolor(color[element1]);
			damage := fight(element1, current);
			if damage < 0 then
				blood1 := blood1 - damage
			else
				blood2 := blood2 - damage;
		end
		else
		begin
			textcolor(color[element2]);
			damage := fight(element2, current);
			if damage < 0 then
				blood2 := blood2 - damage
			else
				blood1 := blood1 - damage;
		end;
		writeln('我方剩余血量：', blood1);
		writeln('敌方剩余血量：', blood2);
		current := not current;
	end;
	if blood1 > 0 then
		writeln('敌方倒下了！我方胜利！！')
	else
		writeln('我方倒下了。我方失败…………')
end.
